package C11_6_ExtractSubclass;

/**
 * @ClassName : JobItem
 * @Description : 提炼子类
 * @Author : wukj1
 * @Date: 2022/8/15
 **/
public class JobItem {
    /** 重构前  */
    private int _unitPrice;
    private int _quantity;
    private Employee _employee;
    private boolean _isLabor;

    public JobItem(int _unitPrice, int _quantity, boolean _isLabor, Employee _employee) {
        this._unitPrice = _unitPrice;
        this._quantity = _quantity;
        this._employee = _employee;
        this._isLabor = _isLabor;
    }

    public int getTotalPrice() {
        return getUnitPrice() * this._quantity;
    }

    public int getUnitPrice() {
        return this._isLabor ? this._employee.getRate() : this._unitPrice;
    }

    public int getQuantity() {
        return this._quantity;
    }

    public Employee getEmployee() {
        return this._employee;
    }



    /**重构后*/
//    private int _unitPrice;
//    private int _quantity;
//
//    protected JobItem(int _unitPrice, int _quantity) {
//        this._unitPrice = _unitPrice;
//        this._quantity = _quantity;
//    }
//
//    public int getTotalPrice() {
//        return getUnitPrice() * this._quantity;
//    }
//
//    public int getUnitPrice() {
//        return this._unitPrice;
//    }

    public static void main(String[] args) {
//        JobItem jobItem = new JobItem(300, 3);
//        System.out.println("jobItem-TotalPrice: " + jobItem.getTotalPrice());
//        JobItem laborItem = new LaborItem(3, new Employee(250));
//        System.out.println("laborItem-TotalPrice: " + laborItem.getTotalPrice());
    }
}
